#region Namespaces

using System.Linq;
using System.Xml;

#endregion

namespace Vibstudio.X4NET.Xml.Linq
{
    public class XComment : XNode
    {
        public XComment(string value)
        {
            Value = value;
        }

        public XComment(XComment other)
        {
            Value = other.Value;
        }

        public override XmlNodeType NodeType
        {
            get { return XmlNodeType.Comment; }
        }

        public string Value { get; set; }

        public override void WriteTo(XmlWriter writer)
        {
            string v = Value.Replace("--", "- -");
            v = v.LastOrDefault() == '-' ? v.Substring(0, v.Length - 1) + "&#2D;" : v;
            writer.WriteComment(v);
        }
    }
}